/*
 *  Copyright 2007 Google Inc.

 * 	Licensed under the Apache License, Version 2.0 (the "License");
 *	you may not use this file except in compliance with the License.
 *	You may obtain a copy of the License at
 
 *  	http://www.apache.org/licenses/LICENSE-2.0

 *	Unless required by applicable law or agreed to in writing, software
 *	distributed under the License is distributed on an "AS IS" BASIS,
 *	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *	See the License for the specific language governing permissions and
 *	limitations under the License.

 */

package com.byjyate.rssdreamwork;

import java.text.*;
import java.util.*;

public class DateTimeProcesser {
	public static Date Parse(String date) {
		if (date == null || date.isEmpty())
			throw new NullPointerException();
		
		DateFormat format1 = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
		DateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		
		Date ans = null;
		try {
			ans = format1.parse(date);
		} catch (ParseException e) {}
		try {
			ans = format2.parse(date);
		} catch (ParseException e) {}
		return ans;

	}

	public static String FormatInChn(Date date) {
		SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		format.setTimeZone(TimeZone.getTimeZone("GMT+8"));
		String m = String.valueOf(date.getTime()%1000);
		while (m.length() < 3)
			m = "0" + m;
		return format.format(date) + "." + m;
	}
	
	private DateTimeProcesser() {
	}
}
